const log4js = require('log4js');
const path = require('path');

const logPath = path.resolve(__dirname, '../bin/日志.log');

/*

const cluster = require('cluster');

let configure = {};

if (cluster.isMaster) {
    configure = {
        appenders: {
            file: { type: 'file', filename: logPath },
            console: { type: 'console' },
            server: {
                type: 'multiprocess', mode: 'master', appender: 'file', loggerHost: '0.0.0.0',
            },
        },
        categories: {
            default: { appenders: ['file', 'console'], level: 'debug' },
        },
    };
} else if (cluster.isWorker) {
    configure = {
        appenders: {
            network: { type: 'multiprocess', mode: 'worker', loggerHost: '0.0.0.0' },
        },
        categories: {
            default: { appenders: ['network'], level: 'debug' },
        },
    };
}
log4js.configure(configure);
*/

/**
 * Note that if you’re just using node core’s cluster module then you don’t need to use this appender
 * log4js will handle logging within the cluster transparently.
 */
log4js.configure({
    appenders: {
        cheese: { type: 'file', filename: logPath },
        console: { type: 'console' },
    },
    categories: { default: { appenders: ['cheese', 'console'], level: 'debug' } },
});

const logger = log4js.getLogger('LOG');

module.exports = logger;
